/*
 * PhanLopInternalFrame.java
 *
 * Created on Jul 25, 2010, 2:41:11 AM
 */

package GUI;

import BUS.HocSinhBUS;
import BUS.HocSinh_LopBUS;
import BUS.LopBUS;
import BUS.NamHocBUS;
import DAO.QuyDinhDAO;
import POJO.HocSinhPOJO;
import POJO.LopPOJO;
import POJO.NamHocPOJO;
import POJO.QuyDinhPOJO;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 * @author
 *  ITEC.HCMUS.EDU.VN
 *  Ngô Huy Đạt
 *  0869005
 *  nhdat.itec@gmail.com
 */
public class XepLopInternalFrame extends javax.swing.JInternalFrame {

    private ArrayList<String> DSMaHocSinh = new ArrayList<String>();
    private ArrayList<String> DSMaLop = new ArrayList<String>();
    private int HSChecked = 0;

    public void loadjLNamHoc(){
        ArrayList<NamHocPOJO> NamHocList = NamHocBUS.selectAll();
        int num = NamHocList.size();
        if(num==0){
            this.jLNamHoc.setText("Danh sách năm học trống.");
        }else{
            this.jLNamHoc.setText(NamHocList.get(num-1).getNamHoc());
        }
    }
    public void loadjCBKhoi(){
        ArrayList<LopPOJO> KhoiList = LopBUS.selectKhoi_NamHoc(this.jLNamHoc.getText());
        DefaultComboBoxModel dcm = new DefaultComboBoxModel();
        for(int i=0;i<KhoiList.size();i++){
            dcm.addElement(KhoiList.get(i).getKhoi());
        }
        if(dcm.getSize()!=0){
            this.jCBKhoi.setModel(dcm);
        }else{
            dcm.addElement("Không có");
            this.jCBKhoi.setModel(dcm);
        }
    }
    public void loadjCBLop(){
        this.DSMaLop.clear();
        DefaultComboBoxModel dcm = new DefaultComboBoxModel();
        if(this.jCBKhoi.getSelectedItem().toString().compareTo("Không có")!=0){
            ArrayList<LopPOJO> LopList = LopBUS.selectLop_Khoi(this.jCBKhoi.getSelectedItem().toString());
            for(int i=0;i<LopList.size();i++){
                this.DSMaLop.add(LopList.get(i).getMaLop());
                dcm.addElement(LopList.get(i).getMaLop());
            }
            if(dcm.getSize()!=0){
                this.jCBLop.setModel(dcm);
            }else{
                dcm.addElement("Không có");
                this.jCBLop.setModel(dcm);
            }
        }else{
            dcm.addElement("Không có");
            this.jCBLop.setModel(dcm);
        }
    }

    public void setjLChucNangDS(){
        if(this.jCheckHocSinh.isSelected()){
            if(this.jTDanhSach.getRowCount()==0){
                this.jLChucNangDS.setText("Lớp chưa có học sinh");
            }else
                this.jLChucNangDS.setText("Chuyển "+this.HSChecked+" học sinh (đã chọn) khỏi lớp "+this.jCBLop.getSelectedItem());
        }else {
            if(this.jTDanhSach.getRowCount()==0){
                this.jLChucNangDS.setText("Không có học sinh mới");
            }else
                this.jLChucNangDS.setText("Xếp "+this.HSChecked+" học sinh (đã chọn) vào lớp "+this.jCBLop.getSelectedItem());
        }
    }

    public void loadjTDanhSach(){
        this.DSMaHocSinh.clear();
        this.HSChecked = 0;
        this.jBLuu.setEnabled(false);
        this.jBHuyBo.setEnabled(false);
        String MaLop = this.DSMaLop.get(this.jCBLop.getSelectedIndex());
        ArrayList<HocSinhPOJO> HSList = HocSinhBUS.selectHocSinh_Lop(MaLop);
        this.jLSiSo.setText(String.valueOf(HSList.size()));
        if(this.jCheckHocSinh.isSelected()==false){
            HSList = HocSinhBUS.selectHocSinh_KoLop();
        }
        DefaultTableModel dtm = new DefaultTableModel() {
            @Override
            public boolean isCellEditable(int row, int col) {
                if(col==0){
                    return true;
                }else{
                    return false;
                }
            }
            @Override
            public Class getColumnClass(int col) {
                if (col == 0) {
                    return Boolean.class;
                } else {
                    return Object.class;
                }
            }
        };
        dtm.addColumn("Chọn");
        dtm.addColumn("Họ và tên");
        dtm.addColumn("Giới tính");
        dtm.addColumn("Năm sinh");
        dtm.addColumn("Địa chỉ");
        dtm.setRowCount(HSList.size());
        for(int i=0;i<HSList.size();i++){
            this.DSMaHocSinh.add(HSList.get(i).getMaHS());
            dtm.setValueAt(false, i, 0);
            dtm.setValueAt(HSList.get(i).getTenHS(), i, 1);
            dtm.setValueAt(HSList.get(i).getGioiTinh(), i, 2);
            String[] temp = HSList.get(i).getNgaySinh().split("-");
            dtm.setValueAt(temp[0], i, 3);
            dtm.setValueAt(HSList.get(i).getDiaChi(), i, 4);
        }
        this.jTDanhSach.setModel(dtm);
        this.jLTongHSTrongDS.setText(String.valueOf(this.jTDanhSach.getRowCount()));
        this.setjLChucNangDS();
    }

    /** Creates new form PhanLopInternalFrame */
    public XepLopInternalFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jCBKhoi = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLSiSo = new javax.swing.JLabel();
        jCheckHocSinh = new javax.swing.JCheckBox();
        jCheckLop = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        jCBLop = new javax.swing.JComboBox();
        jLNamHoc = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLHSMax = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jBLuu = new javax.swing.JButton();
        jBHuyBo = new javax.swing.JButton();
        jBThoat = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTDanhSach = new javax.swing.JTable();
        jLTongHSTrongDS = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLChucNangDS = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("Quản lý học sinh - Lập danh sách lớp");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24));
        jLabel1.setForeground(new java.awt.Color(0, 102, 255));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Lập danh sách lớp");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "1.Chọn lớp", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 51, 204))); // NOI18N

        jLabel2.setText("Năm học:");

        jLabel3.setText("Khối:");

        jCBKhoi.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCBKhoiItemStateChanged(evt);
            }
        });

        jLabel4.setText("Sỉ số:");

        jLSiSo.setText("0");

        jCheckHocSinh.setText("Hiển thị học sinh thuộc lớp");
        jCheckHocSinh.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCheckHocSinhMouseClicked(evt);
            }
        });

        jCheckLop.setText("Chỉ hiển thị lớp chưa đủ học sinh");
        jCheckLop.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCheckLopMouseClicked(evt);
            }
        });

        jLabel6.setText("Lớp:");

        jCBLop.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCBLopItemStateChanged(evt);
            }
        });

        jLNamHoc.setText("loading");

        jLabel7.setText("( Tối đa:");

        jLHSMax.setText("0");

        jLabel9.setText(")");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLNamHoc)
                    .addComponent(jCBKhoi, 0, 142, Short.MAX_VALUE)
                    .addComponent(jCBLop, 0, 142, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckHocSinh)
                    .addComponent(jCheckLop)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLSiSo)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLHSMax)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9)))
                .addGap(18, 18, 18))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLNamHoc)
                    .addComponent(jLSiSo)
                    .addComponent(jLabel4)
                    .addComponent(jLabel7)
                    .addComponent(jLHSMax)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jCBKhoi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckLop))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jCBLop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckHocSinh))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jBLuu.setText("Chấp nhận");
        jBLuu.setEnabled(false);
        jBLuu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBLuuActionPerformed(evt);
            }
        });

        jBHuyBo.setText("Hủy bỏ");
        jBHuyBo.setEnabled(false);
        jBHuyBo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBHuyBoActionPerformed(evt);
            }
        });

        jBThoat.setText("Thoát");
        jBThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBThoatActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "2.Danh sách hoc sinh", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 51, 255))); // NOI18N

        jTDanhSach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTDanhSach.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTDanhSachMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTDanhSach);

        jLTongHSTrongDS.setText("0");

        jLabel5.setText(" -  học sinh");

        jLChucNangDS.setText("Xếp 0 học sinh (đã chọn) vào lớp [lớp] ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLChucNangDS)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 235, Short.MAX_VALUE)
                        .addComponent(jLTongHSTrongDS)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLTongHSTrongDS)
                    .addComponent(jLChucNangDS))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jBHuyBo, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
                            .addComponent(jBLuu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jBThoat, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(174, 174, 174)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(173, 173, 173))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jBLuu)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBHuyBo)
                        .addGap(18, 18, 18)
                        .addComponent(jBThoat))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // set số hoc sinh tối đa
        QuyDinhPOJO qd = QuyDinhDAO.selectAll();
        int HSMax = qd.getHocSinhMax();
        this.jLHSMax.setText(String.valueOf(HSMax));

        this.loadjLNamHoc();
        this.loadjCBKhoi();
        this.loadjCBLop();
        this.loadjTDanhSach();
        this.setjLChucNangDS();
    }//GEN-LAST:event_formInternalFrameOpened

    private void jCBKhoiItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCBKhoiItemStateChanged
        // TODO add your handling code here:
        this.loadjCBLop();
        this.jCheckHocSinhMouseClicked(null);
    }//GEN-LAST:event_jCBKhoiItemStateChanged

    private void jCheckLopMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jCheckLopMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckLopMouseClicked

    private void jCheckHocSinhMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jCheckHocSinhMouseClicked
        // TODO add your handling code here:
        this.setjLChucNangDS();
        this.loadjTDanhSach();
    }//GEN-LAST:event_jCheckHocSinhMouseClicked

    private void jCBLopItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCBLopItemStateChanged
        this.jCheckHocSinhMouseClicked(null);
    }//GEN-LAST:event_jCBLopItemStateChanged

    private void jBThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBThoatActionPerformed
        int xacnhan = JOptionPane.showConfirmDialog(this, "Bạn thực sự muốn thoát ?", "Xác nhận", JOptionPane.YES_NO_OPTION);
        if(xacnhan==0){
            this.dispose();
        }
    }//GEN-LAST:event_jBThoatActionPerformed

    private void jBHuyBoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBHuyBoActionPerformed
        // TODO add your handling code here:
        this.loadjTDanhSach();
    }//GEN-LAST:event_jBHuyBoActionPerformed

    private void jBLuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBLuuActionPerformed
        int num = this.jTDanhSach.getRowCount();
        String MLop = this.DSMaLop.get(this.jCBLop.getSelectedIndex());
        String message = "Đã lập danh sách lớp\n";
        int message_type = JOptionPane.INFORMATION_MESSAGE;
        if(this.jCheckHocSinh.isSelected()){
            int xacnhan = JOptionPane.showConfirmDialog(this, "Bạn thực sự muốn đưa "+this.HSChecked+" học sinh đã chọn\nra khỏi danh sách lớp "+this.jCBLop.getSelectedItem()+"?", "Xác nhận", JOptionPane.YES_NO_OPTION);
            if(xacnhan == 0){
                for(int i=0;i<num;i++){
                    if(this.jTDanhSach.getValueAt(i, 0).equals(true)){
                        String MaHS = this.DSMaHocSinh.get(i);
                        boolean kq = HocSinh_LopBUS.delete(MaHS, MLop);
                        if(kq==false){
                            JOptionPane.showMessageDialog(this, "Ko thể thực hiện thao tác với học sinh\n'"+this.jTDanhSach.getValueAt(i, 1)+"'", "Thông báo", JOptionPane.WARNING_MESSAGE);
                        }
                    }
                }
            }
        }else{
            int xacnhan = JOptionPane.showConfirmDialog(this, "Bạn thực sự muốn đưa "+this.HSChecked+" học sinh đã chọn\nvào danh sách lớp "+this.jCBLop.getSelectedItem()+"?", "Xác nhận", JOptionPane.YES_NO_OPTION);
            if(xacnhan == 0){
                int n = 0;
                for(int i=0;i<num;i++){
                    if(this.jTDanhSach.getValueAt(i, 0).equals(true)){
                        String MaHS = this.DSMaHocSinh.get(i);
                        int kq = HocSinh_LopBUS.insert(MaHS, MLop);
                        if(kq==0){
                            JOptionPane.showMessageDialog(this, "Đã chuyển "+n+" học sinh vào danh sách lớp "+this.jCBLop.getSelectedItem(), "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                            message = "Danh sách lớp đã đầy, ko thể tiếp tục !";
                            message_type = JOptionPane.WARNING_MESSAGE;
                            break;
                        }else if(kq==-1){
                            message += "Xếp lớp thất bại cho học sinh '"+this.jTDanhSach.getValueAt(i, 1)+"'\n";
                            message_type = JOptionPane.ERROR_MESSAGE;
                        }
                        n++;
                    }
                }
                JOptionPane.showMessageDialog(this, message, "Thông báo", message_type);
            }
        }
        this.loadjTDanhSach();
    }//GEN-LAST:event_jBLuuActionPerformed

    private void jTDanhSachMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTDanhSachMouseClicked
        // TODO add your handling code here:
        int num = this.jTDanhSach.getRowCount();
        this.jBLuu.setEnabled(false);
        this.jBHuyBo.setEnabled(false);
        for(int i=0;i<num;i++){
            if(this.jTDanhSach.getValueAt(i, 0).equals(true)){
                this.jBLuu.setEnabled(true);
                this.jBHuyBo.setEnabled(true);
                break;
            }
        }
        this.HSChecked = 0;
        for (int i = 0; i < num; i++) {
            if (this.jTDanhSach.getValueAt(i, 0).equals(true)) {
                this.HSChecked++;
            }
        }
        this.setjLChucNangDS();
    }//GEN-LAST:event_jTDanhSachMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBHuyBo;
    private javax.swing.JButton jBLuu;
    private javax.swing.JButton jBThoat;
    private javax.swing.JComboBox jCBKhoi;
    private javax.swing.JComboBox jCBLop;
    private javax.swing.JCheckBox jCheckHocSinh;
    private javax.swing.JCheckBox jCheckLop;
    private javax.swing.JLabel jLChucNangDS;
    private javax.swing.JLabel jLHSMax;
    private javax.swing.JLabel jLNamHoc;
    private javax.swing.JLabel jLSiSo;
    private javax.swing.JLabel jLTongHSTrongDS;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTDanhSach;
    // End of variables declaration//GEN-END:variables

}
